import Config from './config'
export default {
  mergeUrl (url, baseUrl) {
    var urlMer = Config.baseUrl
    if (Config.dev) {
      return urlMer + url
    } else {
      return url
    }
  },
<<<<<<< HEAD
=======
  getPageHeight () {
    return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
  },
  getPageWidth () {
    return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
  },
>>>>>>> 118bfb24f1cbdee8aba2f4af5269fcf3bfe2e597
  jsonToStr (obj) {
    var str = ''
    for (var key in obj) {
      str += key + '=' + obj[key] + '&'
    }
    return str
  },
  getImgPath (name) {
    return Config.iconPath + name + '.png'
  },
  
  getXY (data) {
    var arr = []
    for (var key in data) {
      arr.push({
        key: key,
        value: data[key]
      })  
    }

    arr.sort(function (a, b) {
      console.log(a.key, b.key, a.key < b.key)
      if (a.key === b.key) {
        return 0
      } else if (a.key < b.key) {
        return -1
      } else {
        return 1
      }
    })

    var XY = {
      dataX: [],
      dataY: []
    }
    console.log('arrr:', arr)
    for (var i = 0; i<arr.length; i++) {
      XY.dataX.push(arr[i].key)
      XY.dataY.push(arr[i].value)
    }

    return XY
  },

  getCookie (name) {
    var arr
    var reg=new RegExp('(^| )' + name + '=([^;]*)(;|$)')
    if (arr = document.cookie.match(reg)) {
      return unescape(arr[2])
    } else {
      return null
    } 
  },
  getNode (nodes, id) {
    for (var i=0; i<nodes.length; i++) {
      if (id === nodes[i]['data']['id']) {
        return nodes[i]['data']
      }
    }
  },
  resetLine () {
    return {
      'width': 1,
      'target-arrow-shape': 'triangle',
      'line-color': '#70c3ea',
      'curve-style': 'haystack',
      'label': 'data(label)',
      'haystack-radius': 9,
      'target-arrow-color': '#70c3ea'
    }
  },
  selectLine () {
    return {
      'width': 1,
      'target-arrow-shape': 'triangle',
      'line-color': 'red',
      'curve-style': 'haystack',
      'label': 'data(label)',
      'haystack-radius': 9,
      'target-arrow-color': 'red'
    }
  }
}
